module Scene {
	/**
	 * 游戏防守场景 ---刘伟
	 * */
	export class SceneDefense extends egret.DisplayObjectContainer {
		public constructor() {
			super();
			this.defenceUI = new Fighter.DefenseUI();
			this.defence = new Fighter.Defense();
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
			this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removeFromStage, this);
		}
		/**地对空防守UI */
		public defenceUI: Fighter.DefenseUI;
		/**防守游戏内容 */
		public defence: Fighter.Defense;

		/**是否进入下一轮 */
		public next_turn: boolean;
		/**判断游戏失败 */
		public gameOver: boolean;

		/**加入舞台 */
		private addToStage(evt: egret.Event) {
			this.gameOver = false;
			this.next_turn = false;
			this.addChild(this.defenceUI);
			this.addChild(this.defence);
			this.addEventListener(egret.Event.ENTER_FRAME, this.updateGameView, this);
		}
		/**离开舞台 */
		private removeFromStage(evt: egret.Event) {
			this.removeEventListener(egret.Event.ENTER_FRAME, this.updateGameView, this);
		}
		/**每帧检测 */
		private updateGameView(evt: egret.Event) {
			if (this.defence.toNextTurn) {
				this.defence.toNextTurn = false;
				// if (this.defence.parent) {
				// 	this.defence.parent.removeChild(this.defence);
				// }
				// if(this.defenceUI.parent)
				// {
				// 	this.defenceUI.parent.removeChild(this.defenceUI);
				// }
				
				this.next_turn = true;
			}
			if (this.defence.is_game_over) {
				this.defence.is_game_over = false;
				this.defence.parent.removeChild(this.defence);
				this.defenceUI.parent.removeChild(this.defenceUI);
				this.gameOver = true;
			}
		}

	}
}